class Level
  include Mongoid::Document
  include Mongoid::Timestamps
  field :name,:type => String
  field :sort,:type => Integer, :default => 0
  field :recommend, :type => Boolean, :default => false
  field :link,:type => String
  #高中，初中，小学，特长



  validates  :name, :presence => true,:uniqueness => true
  validates  :link, :presence => true,:uniqueness => true


  before_validation do
    if self.link.blank?
      name = Charwidth.normalize(self.name)
      name_py = PinYin.of_string(name).join
      self.link = name_py.downcase
    end
  end

  index({ :link => 1}, { :unique => true,:background=>true })
  index :sort => 1
  index :recommend => 1


  has_many :grades
  has_many :linkings
end
